import sys
import pygame

class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __str__(self):
        return f"({self.x}, {self.y})"

    def move(self, dx, dy):
        self.x += dx
        self.y += dy
        return self

    def reset(self):
        self.move(-self.x, -self.y)

class Car:
    def __init__(self, carType=0, marginWidth=0.25, pixelWidth=100, Img=pygame.image):
        self.marginWidth = marginWidth
        self.pixelWidth = pixelWidth
        self.carType = carType
        self.inCheckPoint = Point((5 + marginWidth) * pixelWidth, (3 - carType + marginWidth) * pixelWidth)
        self.entrancePoint = Point((-4 + marginWidth) * pixelWidth, (6 - carType + marginWidth) * pixelWidth)  # 车入口
        self.outCheckPoint = Point((3 - marginWidth) * pixelWidth, (1 - carType - marginWidth) * pixelWidth)
        self.outPoint = Point((12 - marginWidth) * pixelWidth, (-2 - carType - marginWidth) * pixelWidth)  # 车出口
        self.Img = Img
        self.NowEnRect=pygame.Rect(self.entrancePoint.x,self.entrancePoint.y,400,200)
        self.NowoutRect = pygame.Rect(self.outPoint.x, self.outPoint.y, 400, 200)

    def __str__(self):
        return f"({self.inCheckPoint}, {self.outCheckPoint},{self.entrancePoint},{self.outPoint})"

    def setFundInfo(self, carType, marginWidth, pixelWidth):
        self.carType = carType
        self.marginWidth = marginWidth
        self.pixelWidth = pixelWidth
        return self

    def getFundInfo(self):
        return self.carType, self.marginWidth, self.pixelWidth

    def getinCheckPoint(self):
        return self.inCheckPoint

    def getoutCheckPoint(self):
        return self.outCheckPoint
    def getentrancePoint(self):
        return self.entrancePoint
    def getoutPoint(self):
        return self.outPoint


    def getCarImg(self):
        return self.Img

    def getOutPointRect(self):
        return self.NowoutRect
    def getenPointRect(self):
        return self.NowEnRect

class infiniteQueue:
    def __init__(self):
        self.WaitingCars = []

    def is_empty(self):
        return len(self.WaitingCars) == 0

    def enqueue(self, item):
        self.WaitingCars.append(item)

    def dequeue(self):
        if self.is_empty():
            raise Exception("Queue is empty")
        return self.WaitingCars.pop(0)

    def size(self):
        return len(self.WaitingCars)

class Animation:
    def __init__(self,car=Car(), locationA=-1,locationB=0):
        self.car = car
        self.locationA = locationA
        self.locationB = locationB

    def getCar(self):
        return self.car

    def getlocA(self):
        return self.locationA

    def getlocB(self):
        return self.locationB

# class Queue:
#     def __init__(self, max_size):
#         self.max_size = max_size
#         self.queue = []
#
#     def enqueue(self, item):
#         if len(self.queue) < self.max_size:
#             self.queue.append(item)
#         else:
#             print("Queue is full")
#
#     def dequeue(self):
#         if len(self.queue) > 0:
#             return self.queue.pop(0)
#         else:
#             print("Queue is empty")
#
#     def size(self):
#         return len(self.queue)
